<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>
        公告添加
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="css/main.css" media="all">
    <script type="text/javascript" src="lib/loading/okLoading.js"></script>
    <style>
        .imgs{display: none;}
    </style>
    <!--百度编辑器-->
    <script src="ueditor/ueditor.config.js"></script>
    <script src="ueditor/ueditor.all.min.js"></script>
    <script src="ueditor/lang/zh-cn/zh-cn.js"></script>
</head>
<body>

<div class="x-body">
    <form class="layui-form layui-form-pane" action="" id="add">
        <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
            <div class="layui-tab-content" >
                <div class="layui-tab-item layui-show">
                    <input type="hidden" name="op" value="add">
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>活动标题
                        </label>
                        <div class="layui-input-block">
                            <input type="text" name="title" autocomplete="off" placeholder="空制在80个汉字，160个字符以内"
                                   class="layui-input" value="">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>开始时间
                        </label>

                        <div class="layui-input-inline">
                            <input class="layui-input" name="start_time" placeholder="开始时间" id="LAY_demorange_s" value="">
                        </div>

                    </div>

                    <div class="layui-form-item">
                        <label for="link" class="layui-form-label">
                            <span class="x-red">*</span>活动内容
                        </label>
                        <div class="layui-input-inline">
                            <textarea  id="content" placeholder="" name="content" rows="20" cols="60"></textarea>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <button class="layui-btn" type="button" lay-filter="add" lay-submit="">保存 </button>
                    </div>

                    <div style="height:100px;"></div>
                </div>

            </div>

        </div>
    </form>
</div>

<script src="lib/layui/layui.js" charset="utf-8"></script>
<script src="js/x-layui.js" charset="utf-8"></script>

<script type="text/javascript">
    //实例化编辑器
    //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
    //UE.getEditor('content',{initialFrameWidth:750,initialFrameHeight:400,});
</script>

<script>
    layui.use(['laydate','element','layer','form'], function(){
        $ = layui.jquery;//jquery
        lement = layui.element();//面包导航
        layer = layui.layer;//弹出层
        form = layui.form();
        laydate = layui.laydate;//日期插件
        okLoading.close($);
        form.render();
        var start = {
            min: laydate.now()
            ,max: '2099-06-16 23:59:59'
            ,istoday: false
            ,choose: function(datas){
            }
        };
        document.getElementById('LAY_demorange_s').onclick = function(){
            start.elem = this;
            laydate(start);
        };

        
        form.on('submit(add)', function(data){
            var annoTitle=$("input[name='title']").val();
            var annoTime=$("input[name='start_time']").val();
            var annoContent=$("textarea[name='content']").val();

            if(annoTitle==""){
                layer.msg('活动标题不能为空',{icon:5,time:2000});return false;
            }
            if(annoTime==""){
                layer.msg('活动开始时间不能为空',{icon:5,time:2000});return false;
            }
            if(annoContent==""){
                layer.msg('活动内容不能为空',{icon:5,time:2000});return false;
            }
            var data=data.field;
            $.ajax({
            	async : true,
                type:"post",
                url : "${pageContext.request.contextPath}/AnnouncementServlet",
                data:{
                	op : $("input[name='op']").val(),
                	annoTitle : annoTitle,
                	annoTime : annoTime,
                	annoContent : annoContent
                },
                dataType:"json",
                contentType : "application/x-www-form-urlencoded",
                success:function(result){
                    if(result.status == 200){
                        layer.msg(result.message, {icon: 6,time:2000},function () {
                            window.parent.location.reload();
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        });
                        return false;
                    }
                    else{
                        layer.msg(result.message,{icon:5,time:2000});return false;
                    }
                }
            });

        });

    })
</script>

</body>
</html>